<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 父组件模板-->
    <div id="app">
       <cpn @item-click="cpnClick"></cpn>
    </div>

    <!--子组件模板-->
    <template id="cpn">
        <!-- 模板必须有一个根元素-->
        <div>
            <button v-for="item in categorys" @click="btnClick(item)">{{item.name}}</button>
        </div>
    </template>

    <script src="../js/vue.js"></script>
    <script>
        //子组件
        const cpn={
            template:'#cpn',
            data(){
                return {
                    categorys:[
                        {id:'a',name:'热门'},
                        {id:'b',name:'手机'},
                        {id:'c',name:'电器'},
                    ]
                }
            },
            methods:{
                btnClick(item){
                    //发射事件
                    this.$emit('item-click',item)
                   // console.log(item)
                }
            }
        }

          //父组件
          const app=new Vue({
            el:'#app',
            components:{
                cpn
            },
            methods:{
                cpnClick(item){
                    console.log('cpnClick',item)
                }
            }
        })
    </script>
</body>
</html>